import React, { Component } from 'react';
import "../../../styles/Index/Mine/User.scss"
import store from "../../../store/index"

class User extends Component {
    componentDidMount() {
        //监听store中数据的变化,一旦有数据发生改变，会立即执行回调函数
        store.subscribe(() => {
            //更新组件
            this.setState({});
        })
        console.log('aaaaaaaa', store.getState().user.name)
    }
    render() {
        return (
            <div className='user'>
                <div className="user-head">
                    {
                        localStorage.getItem('token') ?
                            <img src="https://img0.baidu.com/it/u=1373794996,3598315245&fm=253&fmt=auto&app=138&f=JPEG?w=332&h=332" alt="" /> :
                            <img src="https://img2.baidu.com/it/u=3969906574,3231239394&fm=253&fmt=auto&app=138&f=PNG?w=500&h=500" alt="" />
                    }
                </div>
                <div className="user-name">{
                    localStorage.getItem('token') ?
                        <div>{store.getState().user.name ? store.getState().user.name : '欢迎回家'}</div> :
                        <div>请登录</div>}</div>
            </div>
        );
    }
}

export default User;